package String;

import java.util.Stack;

public class item1047 {
    public String removeDuplicates(String s) {
        char []c= s.toCharArray();
        Stack<Character> stack = new Stack<>();
        stack.push(c[0]);
        StringBuffer sb = new StringBuffer();
        int i=1;
        while (i<c.length)
        {
            if(stack.isEmpty())
                stack.push(c[i]);
            else {
                char tmp = stack.peek();
                if (c[i] == tmp)
                    stack.pop();
                else
                    stack.push(c[i]);
            }
            i++;
        }
        if(stack.isEmpty())
            return "";
        else {

            while (!stack.isEmpty())
            {
                sb.append(stack.pop());
            }
        }
    return sb.reverse().toString();
    }
}
